package pers.kw.job.server.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import pers.kw.entity.PageDto;
import pers.kw.job.server.dto.log.QueryJobLogReqDto;
import pers.kw.job.server.dto.log.SysJobLogDto;
import pers.kw.job.server.service.SysJobLogService;
import pers.kw.protocol.R;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

@Api(tags = "调度日志操作处理")
@RestController
@RequestMapping("/job/log/api")
public class SysJobLogController {

    @Resource
    private SysJobLogService sysJobLogService;

    @ApiOperation(value = "查询定时任务调度日志列表")
    @PostMapping("list")
    public R<PageDto<SysJobLogDto>> list(QueryJobLogReqDto reqDto) {
        return R.ok(sysJobLogService.selectJobLogList(reqDto));
    }

    @ApiOperation(value = "导出定时任务调度日志列表")
    @PostMapping("export")
    public void export(HttpServletResponse response, QueryJobLogReqDto reqDto) {
        sysJobLogService.export(response, reqDto);
    }

    @ApiOperation(value = "根据调度编号获取详细信息")
    @GetMapping(value = "getInfo/{bizCode}")
    public R<SysJobLogDto> getInfo(@PathVariable String bizCode) {
        return R.ok(sysJobLogService.getJobLogByBizCode(bizCode));
    }

    @ApiOperation(value = "删除定时任务调度日志")
    @DeleteMapping("/{jobLogIds}")
    public R remove(@PathVariable Long[] jobLogIds) {
        sysJobLogService.deleteJobLogByIds(jobLogIds);
        return R.ok();
    }

    @ApiOperation(value = "清空定时任务调度日志")
    @DeleteMapping("/clean")
    public R clean() {
        sysJobLogService.cleanJobLog();
        return R.ok();
    }
}
